import { _decorator, Component, Node } from 'cc';
import { GameController } from '../GameController';
import { ResultEnum } from '../DataCenter/GlobalContext';
import GameInfo from '../DataCenter/GameInfo';
const { ccclass, property } = _decorator;

@ccclass('ResultView')
export class ResultView extends Component {
    @property(Node)
    win: Node = null;
    @property(Node)
    loser: Node = null;
    @property(Node)
    next: Node = null;

    return1Btn: Node = null;
    return2Btn: Node = null;
    return3Btn: Node = null;
    nextBtn: Node = null;

    onLoad(): void {
        this.return1Btn = this.win.getChildByName('return');
        this.return2Btn = this.loser.getChildByName('return');
        this.return3Btn = this.next.getChildByName('return');
        this.nextBtn = this.next.getChildByName('next');
        
        this.return1Btn.on('click', this.onClickRetuenBtn, this);
        this.return2Btn.on('click', this.onClickRetuenBtn, this);
        this.return3Btn.on('click', this.onClickRetuenBtn, this);
        this.nextBtn.on('click', this.onClickNextBtn, this);
    }

    Show(resultView: ResultEnum){
        switch(resultView){
            case ResultEnum.win:
                this.win.active = true;
                this.loser.active = false;
                this.next.active = false;
                break;
            case ResultEnum.loser:
                this.win.active = false;
                this.loser.active = true;
                this.next.active = false;
                break;
            case ResultEnum.next:
                this.win.active = false;
                this.loser.active = false;
                this.next.active = true;
                break;
        }
    }

    onClickRetuenBtn(){
        GameController.inst.showHomeView();
    }

    onClickNextBtn(){
        GameInfo.inst.level++;
        GameController.inst.showBattleView();
    }
}


